// ElasticsearchConfig.cs
using System.Collections.Generic;
using System;

namespace Beauty.Net.Elasticsearch
{
    /// <summary>
    /// Elasticsearch配置类
    /// </summary>
    public class ElasticsearchConfig
    {
        /// <summary>
        /// Elasticsearch节点地址列表
        /// </summary>
        public List<string> Nodes { get; set; } = new List<string>();

        /// <summary>
        /// 用户名
        /// </summary>
        public string? Username { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string? Password { get; set; }

        /// <summary>
        /// 认证类型
        /// </summary>
        public string AuthType { get; set; } = "Basic";

        /// <summary>
        /// 默认索引设置
        /// </summary>
        public IndexSettings DefaultIndexSettings { get; set; } = new IndexSettings();

        /// <summary>
        /// 连接超时时间（毫秒）
        /// </summary>
        public int ConnectionTimeout { get; set; } = 5000;

        /// <summary>
        /// 套接字超时时间（毫秒）
        /// </summary>
        public int SocketTimeout { get; set; } = 30000;

        /// <summary>
        /// 是否启用SSL
        /// </summary>
        public bool EnableSsl { get; set; } = false;

        /// <summary>
        /// 是否验证SSL证书
        /// </summary>
        public bool VerifySslCertificate { get; set; } = true;

        /// <summary>
        /// 最大重试次数
        /// </summary>
        public int MaxRetryCount { get; set; } = 3;

        /// <summary>
        /// 额外配置
        /// </summary>
        public Dictionary<string, string> AdditionalSettings { get; set; } = new Dictionary<string, string>();

        /// <summary>
        /// 获取默认节点（如果没有配置则返回默认地址）
        /// </summary>
        public string GetDefaultNode()
        {
            if (Nodes != null && Nodes.Count > 0)
            {
                return Nodes[0];
            }
            return EnableSsl ? "https://localhost:9200" : "http://localhost:9200";
        }
    }

    /// <summary>
    /// 索引设置
    /// </summary>
    public class IndexSettings
    {
        /// <summary>
        /// 主分片数量
        /// </summary>
        public int NumberOfShards { get; set; } = 1;

        /// <summary>
        /// 副本分片数量
        /// </summary>
        public int NumberOfReplicas { get; set; } = 1;

        /// <summary>
        /// 刷新间隔（毫秒）
        /// </summary>
        public int RefreshInterval { get; set; } = 1000;

        /// <summary>
        /// 索引别名
        /// </summary>
        public List<string> Aliases { get; set; } = new List<string>();

        /// <summary>
        /// 自定义映射设置
        /// </summary>
        public Dictionary<string, object> Mappings { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// 自定义索引设置
        /// </summary>
        public Dictionary<string, object> CustomSettings { get; set; } = new Dictionary<string, object>();
    }
}